package com.amoby.base.commbank.commbiz;

import java.math.BigDecimal;

import com.amoby.base.utils.StringUtil;

public class TrailerRecord {
    // 固定填充的字符串
    private static final String     RECORD_TYPE = "7";
    private static final String     BLANK_12    = StringUtil.leftPad("", 12); // 12个空格
    private static final String     BLANK_24    = StringUtil.leftPad("", 24); // 24个空格
    private static final String     BLANK_40    = StringUtil.leftPad("", 40); // 40个空格
    private static final BigDecimal DECIMAL_100 = new BigDecimal(100);
    /** BSB Number 开户行编号 */
    private String                  bsbNumber;
    /** 总金额（差值） */
    private Double                  netTotalAmount;
    /** 总金额（付款） */
    private Double                  creditTotalAmount;
    /** 总金额（收款） */
    private Double                  debitTotalAmount;
    /** detail recode 的数量 */
    private Integer                 detailCount;

    /**
     * 将信息序列化为字符串
     * 
     * @return 序列化结果
     * @throws IllegalArgumentException 信息有误
     */
    public String serialize() throws IllegalArgumentException {
        StringBuffer sb = new StringBuffer();
        // 序列化常量字符
        sb.append(RECORD_TYPE);
        // 序列化数据字段
        StringUtil.assertSizeEq(bsbNumber, 6);
        sb.append(DirectEntryFile.NUM_FORMAT.format(Long.parseLong(bsbNumber)).replace(',', '-'));
        sb.append(BLANK_12);
        // 序列化金额， 将double金额转换为以分为单位的integer数据
        sb.append(StringUtil.rightJustified(String.valueOf(new BigDecimal(netTotalAmount.toString()).multiply(DECIMAL_100).intValue()), 10, "0"));
        sb.append(StringUtil.rightJustified(String.valueOf(new BigDecimal(creditTotalAmount.toString()).multiply(DECIMAL_100).intValue()), 10, "0"));
        sb.append(StringUtil.rightJustified(String.valueOf(new BigDecimal(debitTotalAmount.toString()).multiply(DECIMAL_100).intValue()), 10, "0"));
        sb.append(BLANK_24);
        sb.append(StringUtil.rightJustified(detailCount.toString(), 6, "0"));
        sb.append(BLANK_40);
        return sb.toString();
    }

    public Double getNetTotalAmount() {
        return this.netTotalAmount;
    }

    public Double getCreditTotalAmount() {
        return this.creditTotalAmount;
    }

    public Double getDebitTotalAmount() {
        return this.debitTotalAmount;
    }

    public void setNetTotalAmount(Double netTotalAmount) {
        this.netTotalAmount = netTotalAmount;
    }

    public void setCreditTotalAmount(Double creditTotalAmount) {
        this.creditTotalAmount = creditTotalAmount;
    }

    public void setDebitTotalAmount(Double debitTotalAmount) {
        this.debitTotalAmount = debitTotalAmount;
    }

    public String getBsbNumber() {
        return this.bsbNumber;
    }

    public Integer getDetailCount() {
        return this.detailCount;
    }

    public void setBsbNumber(String bsbNumber) {
        this.bsbNumber = bsbNumber;
    }

    public void setDetailCount(Integer detailCount) {
        this.detailCount = detailCount;
    }
}
